/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interface_graphique;
import ClassesJava.Cour;
import ClassesJava.Utilisateur;
import static interface_graphique.MenuPrincipale.menu;
import java.util.*;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Rabou abdelfattah
 */
public class Profil extends javax.swing.JFrame {
    Utilisateur listu ;
    DefaultTableModel model = new DefaultTableModel();
    int idu, j;
    /**
     * Creates new form Profil
     */
    public Profil() {
  
        initComponents();
        setLocationRelativeTo(null);
        model.addColumn("ID");
        model.addColumn("NOM");
        model.addColumn("PRENOM");
        model.addColumn("TELEPHONE");
        model.addColumn("EMAIL");
        model.addColumn("LOGIN");
        model.addColumn("MOTE DE PASSE");
        tabuser.setModel(model);
        listu = new Utilisateur();
        afficher();
        afficher(0);

    }
    
    
    public void afficher() {
        model.setRowCount(0);
        Vector<Utilisateur> res = new Vector();
        res = listu.getUtilisateur();
        for (int i = 0; i < res.size(); i++) {
            Object[] e = {res.get(i).getid(), res.get(i).getNom(), res.get(i).getPrenom(), res.get(i).getTel(), res.get(i).getEmail(), res.get(i).getlogin(), res.get(i).getmotedepasse() };
            model.addRow(e);
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtid = new javax.swing.JTextField();
        txtnom = new javax.swing.JTextField();
        txtprenom = new javax.swing.JTextField();
        txttelephone = new javax.swing.JTextField();
        txtemail = new javax.swing.JTextField();
        jBtAjouter1 = new javax.swing.JButton();
        jBtSupprimer1 = new javax.swing.JButton();
        jBtModifier1 = new javax.swing.JButton();
        JbtNouveau = new javax.swing.JButton();
        jBtPremiereElement = new javax.swing.JButton();
        jBtPressident = new javax.swing.JButton();
        jBtSuivent = new javax.swing.JButton();
        jBtDernierElement = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabuser = new javax.swing.JTable();
        txtpass = new javax.swing.JTextField();
        txtlogin = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/jhfv.PNG"))); // NOI18N
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 30, 140, 50));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/dd.PNG"))); // NOI18N
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 110, -1, -1));

        txtid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtidActionPerformed(evt);
            }
        });
        jPanel1.add(txtid, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 120, 150, -1));

        txtnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnomActionPerformed(evt);
            }
        });
        jPanel1.add(txtnom, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 150, 150, 30));
        jPanel1.add(txtprenom, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 190, 150, -1));
        jPanel1.add(txttelephone, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 220, 150, -1));

        txtemail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtemailActionPerformed(evt);
            }
        });
        jPanel1.add(txtemail, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 250, 150, -1));

        jBtAjouter1.setBackground(new java.awt.Color(0, 51, 255));
        jBtAjouter1.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtAjouter1.setForeground(new java.awt.Color(255, 255, 255));
        jBtAjouter1.setText("AJOUTER");
        jBtAjouter1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtAjouter1ActionPerformed(evt);
            }
        });
        jPanel1.add(jBtAjouter1, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 180, 100, 30));

        jBtSupprimer1.setBackground(new java.awt.Color(0, 51, 255));
        jBtSupprimer1.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtSupprimer1.setForeground(new java.awt.Color(255, 255, 255));
        jBtSupprimer1.setText("SUPPRIMER");
        jBtSupprimer1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtSupprimer1ActionPerformed(evt);
            }
        });
        jPanel1.add(jBtSupprimer1, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 300, -1, 30));

        jBtModifier1.setBackground(new java.awt.Color(0, 51, 255));
        jBtModifier1.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtModifier1.setForeground(new java.awt.Color(255, 255, 255));
        jBtModifier1.setText("MODIFIER");
        jBtModifier1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtModifier1ActionPerformed(evt);
            }
        });
        jPanel1.add(jBtModifier1, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 240, 100, 30));

        JbtNouveau.setBackground(new java.awt.Color(51, 102, 255));
        JbtNouveau.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        JbtNouveau.setForeground(new java.awt.Color(255, 255, 255));
        JbtNouveau.setActionCommand("NOUVEAR");
        JbtNouveau.setLabel("Nouveau");
        JbtNouveau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JbtNouveauActionPerformed(evt);
            }
        });
        jPanel1.add(JbtNouveau, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 120, 100, 30));

        jBtPremiereElement.setBackground(new java.awt.Color(0, 102, 255));
        jBtPremiereElement.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtPremiereElement.setForeground(new java.awt.Color(255, 255, 255));
        jBtPremiereElement.setText("<<");
        jBtPremiereElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPremiereElementActionPerformed(evt);
            }
        });
        jPanel1.add(jBtPremiereElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 130, 70, -1));

        jBtPressident.setBackground(new java.awt.Color(0, 102, 255));
        jBtPressident.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtPressident.setForeground(new java.awt.Color(255, 255, 255));
        jBtPressident.setText("<");
        jBtPressident.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPressidentActionPerformed(evt);
            }
        });
        jPanel1.add(jBtPressident, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 170, 70, -1));

        jBtSuivent.setBackground(new java.awt.Color(0, 102, 255));
        jBtSuivent.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtSuivent.setForeground(new java.awt.Color(255, 255, 255));
        jBtSuivent.setText(">");
        jBtSuivent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtSuiventActionPerformed(evt);
            }
        });
        jPanel1.add(jBtSuivent, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 220, 70, -1));

        jBtDernierElement.setBackground(new java.awt.Color(0, 102, 255));
        jBtDernierElement.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        jBtDernierElement.setForeground(new java.awt.Color(255, 255, 255));
        jBtDernierElement.setText(">>");
        jBtDernierElement.setActionCommand("");
        jBtDernierElement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtDernierElementActionPerformed(evt);
            }
        });
        jPanel1.add(jBtDernierElement, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 260, 70, -1));

        tabuser.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 255, 204)));
        tabuser.setFont(new java.awt.Font("Tempus Sans ITC", 3, 12)); // NOI18N
        tabuser.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID", "NOM", "PRENOM", "TELEPHONE", "EMAIL", "LOGIN"
            }
        ));
        tabuser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabuserMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tabuser);

        jPanel1.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 360, 600, 140));
        jPanel1.add(txtpass, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 310, 150, -1));
        jPanel1.add(txtlogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 280, 150, -1));

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/people.png"))); // NOI18N
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, -10, 140, 140));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/fond_ecran_wallpaper_25.jpg"))); // NOI18N
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 660, 500));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

      public void afficher(int i) {
        idu = (int) model.getValueAt(i, 0);
        txtid.setText(model.getValueAt(i, 0).toString());
        txtnom.setText(model.getValueAt(i, 1).toString());
        txtprenom.setText(model.getValueAt(i, 2).toString());
        txttelephone.setText(model.getValueAt(i, 3).toString());
        txtemail.setText(model.getValueAt(i, 4).toString());
        txtlogin.setText(model.getValueAt(i, 5).toString());
        txtpass.setText(model.getValueAt(i, 6).toString());
    }
    
    
    private void txtidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtidActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtidActionPerformed

    private void txtnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnomActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtnomActionPerformed

    private void txtemailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtemailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtemailActionPerformed

    private void jBtAjouter1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtAjouter1ActionPerformed
        // booton Ajouter
           int i;
        Utilisateur f;
        f = new Utilisateur(0, txtnom.getText(), txtprenom.getText(),txttelephone.getText(),txtemail.getText(),txtlogin.getText(),txtpass.getText());
        i = f.ajouterUtilisateur(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Un nouveau utilisateur est bien enregistré", "Ajouter un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
           
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec d'ajouter nouveau utilisateur", "Ajouter un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtAjouter1ActionPerformed

    private void jBtSupprimer1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtSupprimer1ActionPerformed
        //botton suppriler
int i;
        Utilisateur f;
        f = new Utilisateur(idu, txtnom.getText(), txtprenom.getText(),txttelephone.getText(),txtemail.getText(),txtlogin.getText(),txtpass.getText());
        i = f.supprimerUtilisateur(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "Un utilisateur est bien Supprimer", "Supprimer un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de supprimer utilisateur", "Supprimer un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtSupprimer1ActionPerformed

    private void jBtModifier1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtModifier1ActionPerformed
        // booton Modifier
         int i;
        Utilisateur f;
        f = new Utilisateur(idu, txtnom.getText(), txtprenom.getText(), txttelephone.getText(), txtemail.getText(), txtlogin.getText(), txtpass.getText() );
        i = f.modifierUtilisateur(f);
        if (i == 1) {
            afficher();
            javax.swing.JOptionPane.showMessageDialog(null, "L'utilisateur est bien Modifier", "Modifier un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            javax.swing.JOptionPane.showMessageDialog(null, "echec de Modifier l'utilisateur", "Modifier un utilisateur", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_jBtModifier1ActionPerformed

    private void JbtNouveauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbtNouveauActionPerformed
        // booton Nouveau
        txtid.setText("");
        txtnom.setText("");
        txtprenom.setText("");
        txttelephone.setText("");
        txtemail.setText("");
        txtlogin.setText("");
        txtpass.setText("");
       
    }//GEN-LAST:event_JbtNouveauActionPerformed

    private void jBtPremiereElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPremiereElementActionPerformed
 j = 0;
        afficher(j);
    }//GEN-LAST:event_jBtPremiereElementActionPerformed

    private void jBtPressidentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPressidentActionPerformed
 if (j > 0) {
            j--;
            afficher(j);
 }
    }//GEN-LAST:event_jBtPressidentActionPerformed

    private void jBtSuiventActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtSuiventActionPerformed
 if (j < tabuser.getRowCount() - 1) {
            j++;
            afficher(j);
        }
    }//GEN-LAST:event_jBtSuiventActionPerformed

    private void jBtDernierElementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtDernierElementActionPerformed
  j = tabuser.getRowCount() - 1;
        afficher(j);
    }//GEN-LAST:event_jBtDernierElementActionPerformed

    private void tabuserMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabuserMouseClicked
        j = tabuser.getSelectedRow();
        afficher(j);
    }//GEN-LAST:event_tabuserMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Profil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Profil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Profil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Profil.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Profil().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JbtNouveau;
    private javax.swing.JButton jBtAjouter1;
    private javax.swing.JButton jBtDernierElement;
    private javax.swing.JButton jBtModifier1;
    private javax.swing.JButton jBtPremiereElement;
    private javax.swing.JButton jBtPressident;
    private javax.swing.JButton jBtSuivent;
    private javax.swing.JButton jBtSupprimer1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tabuser;
    private javax.swing.JTextField txtemail;
    private javax.swing.JTextField txtid;
    private javax.swing.JTextField txtlogin;
    private javax.swing.JTextField txtnom;
    private javax.swing.JTextField txtpass;
    private javax.swing.JTextField txtprenom;
    private javax.swing.JTextField txttelephone;
    // End of variables declaration//GEN-END:variables
}
